package com.itany.corejava.code07_面向对象.继承;

/**
 * @author MissChen
 * @version 1.0
 * @date 2023 年11月02日 15:16
 */
public class Person {
    private String name;
    private int age;
    private String gender;
    public void setName(String name){
        this.name=name;
    }
    public String getName(){
        return name;
    }
    public void setAge(int age){
        this.age=age;
    }
    public int getAge(){
        return age;
    }
    public void setGender(String gender){
        this.gender=gender;
    }
    public String getGender(){
        return gender;
    }
    public void show(){
        System.out.println("姓名是:"+name+",年龄:"+age+",性别:"+gender);
    }
}
class Man extends Person{
    private double salary;
    public void setSalary(double salary){
        this.salary=salary;
    }
    public double getSalary(){
        return salary;
    }
    public void work(){
        System.out.println("我是一个男人,我需要好好努力赚钱，取媳妇,我每个月赚"+salary+"元");
    }

}
class Woman extends Person{
    private int appearance;//外貌颜值
    public void setAppearance(int appearance){
        this.appearance=appearance;
    }
    public int getAppearance(){
        return appearance;
    }
    public void shopping(){
        System.out.println("我是一个女孩,我的颜值是"+appearance+",我喜欢买买买，吃吃吃，喝喝喝");
    }
}
//猫继承人不合理，实际开发中建议不要出现
// class Cat extends  Person{
//
// }

class TestPerson{
    public static void main(String[] args) {
        Man man=new Man();

        //调用父类方法
        man.setName("王四");
        man.setAge(30);
        man.setGender("男");
        man.show();

        //调用子类方法(自己独有的方法)
        man.setSalary(10000);
        man.work();

        Woman woman=new Woman();
        //调用父类方法
        woman.setName("马凡娟");
        woman.setAge(20);
        woman.setGender("女");

        //调用子类方法(自己独有的方法)
        woman.setAppearance(100);
        woman.shopping();


        /*
        结论:
            子类继承父类，将会继承父类中已有的属性与方法
                可以将多个子类中所有的相同属性与方法定义在父类中
                子类也可以具有自己独有的属性与方法，此时当前子类自己调用

               Java只支持单继承。 即: 一个子类最多只能继承一个父类
               B继承A，C继承B，C继承A和B的属性和方法


                 D类没有继承任何类
                    默认继承了Object类
                    Java中所有的类都直接或者间接的继承java.lang.Object
         */

        C c=new C();
        System.out.println(c.getName());
        System.out.println(c.getAddress());



        D d=new D();
        d.toString();

    }
}

class A{
    private String name="alice";
    public void setName(String name){
        this.name=name;
    }
    public String getName(){
        return name;
    }
}
class B extends A{
    private String address="南京";
    public void setAddress(String address){
        this.address=address;
    }
    public String getAddress(){
        return address;
    }
}
class C extends B{

}
class D{

}